package com.coderman.basketball.infrast.gatawayimpl.trade;

import com.coderman.basketball.domain.gataway.trade.ContractService;
import com.coderman.basketball.domain.model.trade.bo.ContractBO;
import com.coderman.basketball.infrast.converter.trade.ContractConverter;
import com.coderman.basketball.infrast.dao.dataobject.contract.ContractDetailDO;
import com.coderman.basketball.infrast.dao.dataobject.contract.ContractSignRecordDO;
import com.coderman.basketball.infrast.dao.dataobject.member.TeamPlayerDO;
import com.coderman.basketball.infrast.dao.mapper.member.PlayerMapper;
import com.coderman.basketball.infrast.dao.mapper.member.TeamPlayerMapper;
import com.coderman.basketball.infrast.dao.mapper.trade.ContractDetailMapper;
import com.coderman.basketball.infrast.dao.mapper.trade.ContractMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description:
 * date: 2021/5/20
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Service
public class ContractServiceImpl implements ContractService {

    @Resource
    private ContractMapper contractMapper;

    @Resource
    private TeamPlayerMapper teamPlayerMapper;

    @Resource
    private ContractDetailMapper contractDetailMapper;

    @Override
    public String signWithinTeamPlayer(ContractBO contractBO) {
        TeamPlayerDO teamPlayerDO = new TeamPlayerDO();
        teamPlayerDO.setTeamName(contractBO.getTeamSignName());
        teamPlayerDO.setPlayerId(contractBO.getPlayerId());
        teamPlayerDO.setPlayerName(contractBO.getPlayerName());
        teamPlayerDO.setStartTime(contractBO.getEffectDate());
        teamPlayerDO.setEndTime(contractBO.getInEffectDate());
        teamPlayerDO.setStatus(0);
        teamPlayerMapper.insert(teamPlayerDO);

        ContractSignRecordDO contractSignRecordDO = ContractConverter.INSTANCE.bo2do(contractBO);
        contractMapper.insert(contractSignRecordDO);
        List<ContractDetailDO> contractDetailDOList = ContractConverter.INSTANCE.bo2do(contractBO.getContractDetailBOList());
        for (ContractDetailDO contractDetailDO : contractDetailDOList){
            contractDetailMapper.insert(contractDetailDO);
        }

        return null;
    }
}
